package com.anjubao.parking.municipal.basezone.controller;

import com.anjubao.parking.municipal.basezone.dto.CitiesResDto;
import com.anjubao.parking.municipal.basezone.dto.DefaultCityResDto;
import com.anjubao.parking.municipal.basezone.dto.DistrictsResDto;
import com.anjubao.parking.municipal.basezone.dto.ProvincesResDto;
import com.anjubao.parking.municipal.basezone.feign.BaseZoneFeginService;
import com.anjubao.parking.municipal.basezone.service.BaseZoneService;
import com.anjubao.parking.municipal.common.dto.ApiResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author anjubao
 */
@RestController
@RequestMapping("/base-zone")
public class BaseZoneController implements BaseZoneFeginService {

    @Autowired
    private BaseZoneService baseZoneService;
    /**
     * 获取省份数据
     * @return
     */
    @GetMapping("/provinces")
    @ApiOperation(value = "获取省份数据",notes = "",code = 2000)
    @ApiResponses(value = {
            @ApiResponse(code = 5000, message = "Internal Server Error"),
    })
    public ApiResult<List<ProvincesResDto>> getProvinces(){
        return ApiResult.success(baseZoneService.getProvinces());
    }

    /**
     * 获取城市数据
     * @param provinceId 省份ID
     * @return
     */
    @GetMapping("/cities")
    @ApiOperation(value = "获取城市数据",notes = "",code = 2000)
    @ApiImplicitParams({
            @ApiImplicitParam(name="provinceId",value = "省份Id",required = true,dataType = "int",example = "44",paramType = "query")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 5000, message = "Internal Server Error"),
    })
    public ApiResult<List<CitiesResDto>> getCities(@RequestParam("provinceId") int provinceId){
        return ApiResult.success(baseZoneService.getCities(provinceId));
    }

    /**
     * 获取区域数据
     * @param cityId 城市Id
     * @return
     */
    @GetMapping("/districts")
    @ApiOperation(value = "获取区域数据",notes = "",code = 2000)
    @ApiImplicitParams({
            @ApiImplicitParam(name="cityId",value = "城市Id",required = true,dataType = "int",example = "4401",paramType = "query")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 5000, message = "Internal Server Error"),
    })
    @Override
    public ApiResult<List<DistrictsResDto>> getDistricts(@RequestParam("cityId")  int cityId){
        return ApiResult.success(baseZoneService.getDistricts(cityId));
    }

    /**
     * 设置默认城市信息
     * @return
     */
    @PostMapping("/default-city")
    @ApiOperation(value = "设置默认城市",notes = "",code = 2000)
    @ApiImplicitParams({
            @ApiImplicitParam(name="cityId",value = "城市Id",required = true,dataType = "int",example = "4401",paramType = "query")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 5000, message = "Internal Server Error"),
    })
    public ApiResult<DefaultCityResDto> setDefaultCity(@RequestParam("cityId")  int cityId){
        return ApiResult.success(baseZoneService.setDefaultCity(cityId));
    }

    /**
     * 获取默认城市信息
     * @return
     */
    @GetMapping("/default-city")
    @ApiOperation(value = "获取默认城市信息",notes = "",code = 2000)
    @ApiResponses(value = {
            @ApiResponse(code = 5000, message = "Internal Server Error"),
    })
    @Override
    public ApiResult<DefaultCityResDto> getDefaultCity(){
        return ApiResult.success(baseZoneService.getDefaultCity());
    }
}
